package com.app.webservice;

import java.util.ArrayList;
import java.util.List;

import com.app.entidades.Bandas;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonParser;

public class ListaBandas {

	private static String URI = "http://lucianokikao.com.br/mobile/";

	public List<Bandas> getBandas() throws Exception {

		String[] json = new WebServiceApp().get(URI
				+ "bandas.php?user=q1w2e3r4t5&pass=t5r4e3w2q1");
		List<Bandas> bandas = new ArrayList<Bandas>();

		if (json[0].equals("200")) {
			Gson gson = new Gson();
			JsonParser parser = new JsonParser();

			JsonArray array = parser.parse(json[1]).getAsJsonArray();

			for (int i = 0; i < array.size(); i++) {
				bandas.add(gson.fromJson(array.get(i), Bandas.class));
			}
			return bandas;
		} else {
			throw new Exception(json[1]);
		}

	}

}
